---
title: "Gartzke&Hulme_ISQ_2020"
author: "Patrick Hulme"
date: "8/15/2020"
output: html_document
---




```{r include=FALSE}
rm(list=ls())

library(readr)
MIDandLOCandOutcome1 <- read_csv("/Users/patrickhulme/Dropbox/UCSD/Working_Papers/Paper1/RMD_Latex/ISQA/DF_5pt.csv")
```










```{r}
#FIGURE 1
#adjusted Scale
library(ggplot2)
library(plyr)
library(dplyr)
x = count(MIDandLOCandOutcome1, USA_Outcome)

x$freq <- x$n

x$Outcome_freq <-  (x$freq/(colSums(x[2])))
x$adj_USA_Outcome <- 3 + (x$USA_Outcome-3)*((x$Outcome_freq)^(1/5))



MIDandLOCandOutcome1$adj_USA_Outcome[MIDandLOCandOutcome1$USA_Outcome==1] <- x$adj_USA_Outcome[x$USA_Outcome==1]
MIDandLOCandOutcome1$adj_USA_Outcome[MIDandLOCandOutcome1$USA_Outcome==2] <- x$adj_USA_Outcome[x$USA_Outcome==2]
MIDandLOCandOutcome1$adj_USA_Outcome[MIDandLOCandOutcome1$USA_Outcome==3] <- x$adj_USA_Outcome[x$USA_Outcome==3]
MIDandLOCandOutcome1$adj_USA_Outcome[MIDandLOCandOutcome1$USA_Outcome==4] <- x$adj_USA_Outcome[x$USA_Outcome==4]
MIDandLOCandOutcome1$adj_USA_Outcome[MIDandLOCandOutcome1$USA_Outcome==5] <- x$adj_USA_Outcome[x$USA_Outcome==5]


library(extrafont)

YLabels <- c("U.S. Loss","U.S. Yield", "Indeterminate", "Opponent Yield", "U.S. Win")
ggplot(data = MIDandLOCandOutcome1, mapping = aes(x = styear.x, y = adj_USA_Outcome)) + geom_point(size=1.5, alpha = 1) +  labs(x="Year",y="U.S. Outcome") +
  theme(axis.text = element_text(size = 18), axis.title = element_text(size = 24),  axis.title.y =  element_text(margin = margin(r = 30)), axis.title.x =  element_text(margin = margin(t = 20)), panel.background = element_blank(),axis.line = element_line(colour = "black")) + scale_y_continuous(breaks = x$adj_USA_Outcome, labels=c("U.S. Loss","U.S. Yield","Indeterminate","Opponent Yield","U.S. Win")) +
  #ggtitle('USA MIDs', subtitle = 'Outcomes over Time') +
  geom_smooth(se=F, size = 1, linetype="dashed", color = "black") + geom_smooth(method='lm', color = "black", se=F, size = 1)+
  theme(text=element_text(size=12, family="Times"))

```





```{r}
#FIGURE 2
#adjusted Scale
ArmedConflictandLOCandOutcome1 <- subset(MIDandLOCandOutcome1, hiact.x > 12 & hiact.x < 22) 
x_UoF = count(ArmedConflictandLOCandOutcome1, USA_Outcome)
x_UoF$freq <- x_UoF$n
x_UoF$Outcome_freq <-  (x_UoF$freq/(colSums(x_UoF[2])))
x_UoF$adj_USA_Outcome <- 3 + (x_UoF$USA_Outcome-3)*((x_UoF$Outcome_freq)^(1/2))


ArmedConflictandLOCandOutcome1$adj_USA_Outcome[ArmedConflictandLOCandOutcome1$USA_Outcome==1] <- x_UoF$adj_USA_Outcome[x_UoF$USA_Outcome==1]
ArmedConflictandLOCandOutcome1$adj_USA_Outcome[ArmedConflictandLOCandOutcome1$USA_Outcome==2] <- x_UoF$adj_USA_Outcome[x_UoF$USA_Outcome==2]
ArmedConflictandLOCandOutcome1$adj_USA_Outcome[ArmedConflictandLOCandOutcome1$USA_Outcome==3] <- x_UoF$adj_USA_Outcome[x_UoF$USA_Outcome==3]
ArmedConflictandLOCandOutcome1$adj_USA_Outcome[ArmedConflictandLOCandOutcome1$USA_Outcome==4] <- x_UoF$adj_USA_Outcome[x_UoF$USA_Outcome==4]
ArmedConflictandLOCandOutcome1$adj_USA_Outcome[ArmedConflictandLOCandOutcome1$USA_Outcome==5] <- x_UoF$adj_USA_Outcome[x_UoF$USA_Outcome==5]

library(extrafont)

ggplot(data = ArmedConflictandLOCandOutcome1, mapping = aes(x = styear.x, y = adj_USA_Outcome)) + geom_point(size=1.5) +  labs(x="Year",y="U.S. Outcome") +
  theme(axis.text = element_text(size = 18), axis.title = element_text(size = 24), axis.title.y =  element_text(margin = margin(r = 30)), axis.title.x =  element_text(margin = margin(t = 20)), panel.background = element_blank(),axis.line = element_line(colour = "black")) + scale_y_continuous(breaks = x_UoF$adj_USA_Outcome, labels=c("U.S. Loss","Indeterminate","Opponent\nYield","U.S. Win")) +
  #ggtitle('USA Uses of Force', subtitle = 'Outcomes over Time') +
  geom_smooth(se=F, size = 1, linetype="dashed", color = "black") + geom_smooth(method='lm', color = "black", se=F, size = 1)+
  theme(text=element_text(size=12, family="Times"))
```




```{r, message=FALSE, warning=FALSE}
#FIGURE 3
ggplot(data = MIDandLOCandOutcome1, mapping = aes(x = styear.x, y = DCDIst)) + geom_point(size=1.5) + labs(x="Year",y="Distance (Miles)") +
  theme(axis.text = element_text(size = 18), axis.title = element_text(size = 24), axis.title.y =  element_text(margin = margin(r = 30)), axis.title.x =  element_text(margin = margin(t = 20)), panel.background = element_blank(),axis.line = element_line(colour = "black")) + 
  scale_y_log10(breaks=c(200,500,1000,2000,5000,10000),labels=c(200,500,1000,2000,5000,10000)) + 
  #ggtitle('US MIDs Distances', subtitle = 'Distance from Washington, DC') +
 geom_smooth(method='lm', color = "black", size = 1)+
  geom_smooth(size = 1, linetype="dashed", color = "black") +
  theme(text=element_text(size=12, family="Times"))
```






```{r}
#FIGURE 4
ggplot(data = ArmedConflictandLOCandOutcome1, mapping = aes(x = styear.x, y = DCDIst)) + geom_point(size=1.5) +  labs(x="Year",y="Distance (Miles)") +
  theme(axis.text = element_text(size = 18), axis.title = element_text(size = 24), axis.title.y =  element_text(margin = margin(r = 30)), axis.title.x =  element_text(margin = margin(t = 20)), panel.background = element_blank(),axis.line = element_line(colour = "black")) + 
  scale_y_log10(breaks=c(200,500,1000,2000,5000,10000),labels=c(200,500,1000,2000,5000,10000)) + 
  #ggtitle('US Uses of Force Distances', subtitle = 'Distance from Washington, DC') + 
  geom_smooth(method='lm', color = "black", size = 1)+
  geom_smooth(size = 1, linetype="dashed", color = "black") +
  theme(text=element_text(size=12, family="Times"))
```








```{r}
#FIGURE 5
library(extrafont)
ggplot(data = MIDandLOCandOutcome1, mapping = aes(x = DCDIst, y = adj_USA_Outcome)) + geom_point(size=1.5) +  labs(x="Distance (Miles)",y="U.S. Outcome") +
  theme(axis.text = element_text(size = 18), axis.title = element_text(size = 24), axis.title.y =  element_text(margin = margin(r = 30)), axis.title.x =  element_text(margin = margin(t = 20)), panel.background = element_blank(),axis.line = element_line(colour = "black")) + 
  #ggtitle('U.S. MIDs Distances and Outcomes') + 
  geom_smooth(method='lm', color = "black", se=F, size = 1)+
  geom_smooth(se=F, size = 1, linetype="dashed", color = "black") + scale_y_continuous(breaks = x$adj_USA_Outcome, labels=c("U.S. Loss","U.S. Yield","Indeterminate","Opponent Yield","U.S. Win")) + scale_x_log10(breaks=c(200,500,1000,2000,5000,10000),labels=c(200,500,1000,2000,5000,10000))+
  theme(text=element_text(size=12, family="Times"))
```















```{r}
#FIGURE 6


ggplot(data = ArmedConflictandLOCandOutcome1, mapping = aes(x = DCDIst, y = adj_USA_Outcome)) + geom_point(size=1.5) +  labs(x="Distance (Miles)",y="U.S. Outcome") +
  theme(axis.text = element_text(size = 18), axis.title = element_text(size = 24), axis.title.y =  element_text(margin = margin(r = 30)), axis.title.x =  element_text(margin = margin(t = 20)), axis.text.x = element_text(hjust = 0.6), panel.background = element_blank(),axis.line = element_line(colour = "black")) + 
  #ggtitle('US Uses of Force Distances and Outcomes') + 
  geom_smooth(method='lm', color = "black", se=F, size = 1)+
  geom_smooth(se=F, size = 1, linetype="dashed", color = "black") + scale_y_continuous(breaks = x_UoF$adj_USA_Outcome, labels=c("U.S. Loss","Indeterminate","Opponent\nYield","U.S. Win"))+scale_x_log10(breaks=c(200,500,1000,2000,5000,10000),labels=c(200,500,1000,2000,5000,10000))+
  theme(text=element_text(size=12, family="Times"))
```





```{r}
#FIGURE 7
library(rms)
MIDandLOCandOutcome1$USA_Outcome <- as.numeric(MIDandLOCandOutcome1$USA_Outcome)
par(mfrow=c(3,2))
plot.xmean.ordinaly(USA_Outcome ~ styear.x + log10(DCDIst) + cinc + hostlev.x + concurrent, data = MIDandLOCandOutcome1)

MIDandLOCandOutcome1$USA_Outcome <- as.factor(MIDandLOCandOutcome1$USA_Outcome)
#dev.off()

```





```{r}
#FIGURE 8

library(rms)
ArmedConflictandLOCandOutcome1$USA_Outcome <- as.numeric(ArmedConflictandLOCandOutcome1$USA_Outcome)
par(mfrow=c(3,2))
plot.xmean.ordinaly(USA_Outcome ~ styear.x + log10(DCDIst) + cinc + hostlev.x + concurrent, data = ArmedConflictandLOCandOutcome1)

ArmedConflictandLOCandOutcome1$USA_Outcome <- as.factor(ArmedConflictandLOCandOutcome1$USA_Outcome)
```

